package svc

import (
	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"my-zero-tiktok/apps/video/models"
	"my-zero-tiktok/apps/video/rpc/internal/config"
)

type ServiceContext struct {
	Config        config.Config
	Cache         cache.Cache
	Conn          sqlx.SqlConn
	Redis         *redis.Redis
	VideoModel    models.VideoModel
	FavVideoModel models.FavoriteModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.DataBase.MySQL)
	return &ServiceContext{
		Config:        c,
		Conn:          conn,
		Redis:         redis.MustNewRedis(c.GeneralRedis),
		VideoModel:    models.NewVideoModel(conn, c.CacheRedis),
		FavVideoModel: models.NewFavoriteModel(conn, c.CacheRedis),
	}
}
